﻿using System;
using System.Web.UI.WebControls;
using AB.ServiceDirectory.Commons.DataFilters;

namespace AB.ServiceDirectory.Design.Org
{
    public partial class ASupportingMaterials : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // LoadAllOrganisation();
                var filter = new ASupportingMaterialFilter();
                ViewState["filter"] = filter;

            }
        }

        protected void ButtonInactive_Command(object sender, CommandEventArgs e)
        {
            throw new NotImplementedException();
        }

        protected void ButtonSave_Command(object sender, CommandEventArgs e)
        {
            throw new NotImplementedException();
        }


        protected void ButtonLookup_Command(object sender, CommandEventArgs e)
        {
            throw new NotImplementedException();
        }

        protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            var filter = ViewState["filter"] as ASupportingMaterialFilter;
            e.InputParameters["filter"] = filter;
        }


       protected void CheckBoxInactive_CheckedChanged(object sender, EventArgs e)
       {
           var filter = ViewState["filter"] as ASupportingMaterialFilter;
           if (filter != null)
           {
               filter.IsActive = CheckBoxInactive.Checked;
               GridViewSupportingMaterials.DataBind();
           }
       }
         protected void LinkButtonURL_Command(object sender, CommandEventArgs e)
        {
             if(e.CommandArgument.Equals("True"))
             {
                 Response.Redirect(string.Format("~/Organisation/EditASupportingMaterials.aspx?id={0}", e.CommandName));
             }
             else
             {
                 BO.ASupportingMaterialBo.UpdateStatus(int.Parse(e.CommandName), true);
                 Response.Redirect(string.Format("~/Organisation/EditASupportingMaterials.aspx?id={0}", e.CommandName));
             }
        }

        protected void GridViewSupportingMaterials_RowCreated(object sender, GridViewRowEventArgs e)
       {
         var supportingMaterial = e.Row.DataItem as Entities.SupportingMaterial;
         if(supportingMaterial!=null)
         {
             if(!supportingMaterial.IsActive)
             {
                 e.Row.Attributes["onclick"] = "return Confirm_Edit();";
             }
         }
       }


    }
}